#include "bsp.h"

void BSP_Init() {
    int ret = 0;
    // LED_Init();
    //  串口初始化
    UART_Init(USART1_INDEX, 115200, 0); // Debug串口

#ifdef ENABLE_DEBUG_SERIAL_DMA_TX
    DMA_Init(DMA2_Stream7, DMA_CHANNEL_4); /* 初始化DMA */
    HAL_UART_Transmit_DMA(&GetUartHandle(USART1_INDEX)->huart, "USART-DMA Init Finish\r\n", strlen("USART-DMA Init Finish\r\n"));
    delay_ms(100);
    HAL_UART_DMAStop(&GetUartHandle(USART1_INDEX)->huart); /* 传输完成以后关闭串口DMA */
#endif

#ifdef ENABLE_LCD_SHOW_IMAGE
    LCD_Init();
    LCDShowString(10, 250, 500, 32, 32, "SunTracker", RED);
    LCDShowString(10, 282, 220, 24, 24, "Build Time:", RED);
    LCDShowString(10, 306, 220, 24, 24, __DATE__, RED);
    LCDShowString(10, 330, 220, 24, 24, __TIME__, RED);
#endif
    LOG("Compiled on: %s at %s\r\n", __DATE__, __TIME__);
    ret = OV7670_Init();
    if (ret != OV7670_EOK) {
        LOG("OV7670 Init Failed!\r\n");
#ifdef ENABLE_LCD_SHOW_IMAGE
        LCDShowString(10, 300, 220, 32, 32, "OV7670 Init Failed!", RED);
#endif
        while (1) {
            delay_ms(200);
        }
    }
}
